﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.DataHub
{
    /// <summary>
    /// 岗位服务
    /// </summary>
    public class PosInfoService : CrudAppService<PosInfo, PosInfoDto, Guid, PosInfoInput, PosInfoCreateDto, PosInfoUpdateDto>, IPosInfoService
    {
        private IRepository<PosInfo, Guid> _drugPrdrRepository;

        public PosInfoService(IRepository<PosInfo, Guid> drugPrdrRepository) : base(drugPrdrRepository)
        {
            _drugPrdrRepository = drugPrdrRepository;
        }

        /// <summary>
        /// 获取岗位列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<PosInfoDto>> GetListAsync(PosInfoInput input)
        {
            var iQuery = await _drugPrdrRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<PosInfo>, List<PosInfoDto>>(iQuery.ToList());

                return new PagedResultDto<PosInfoDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<PosInfo>, List<PosInfoDto>>(items.ToList());

                return new PagedResultDto<PosInfoDto>(totalCount, itemsDto);
            }
        }
    }
}
